//
//  HSLNavigationController.swift
//  HSLMicroBlog
//
//  Created by mac on 15/12/8.
//  Copyright © 2015年 HSL. All rights reserved.
//

import UIKit

class HSLNavigationController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
        
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {

        if childViewControllers.count != 0 {
            var title:String = "返回"
            if childViewControllers.count == 1 {
                title = childViewControllers.first!.title ?? title
            }
            //设置左侧返回按钮
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: "navigationbar_back_withtext", title: title, target: self, action: "back")
            //隐藏tabBar
            viewController.hidesBottomBarWhenPushed = true
            //设置标题
            viewController.navigationItem.title = "当前是第\(childViewControllers.count + 1)级控制器"
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func back() {
        popViewControllerAnimated(true)
    }
    
    // MARK: - 
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count != 1
        
    }
}
